﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Maticsoft.DBUtility;
using System.Data.SqlClient;

namespace ElingOA6_Admin_DSJCJ.DAL
{
    public class MonthPlanSummary
    {

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(decimal year, decimal month, string emplNo, string entityNo, string type)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from dbo.t_MonthPlanSummary");
            strSql.Append(" where FYear=@FYear and FMonth=@FMonth and FEmplNo=@FEmplNo and FEntityNo=@FEntityNo and FType=@FType");
            SqlParameter[] parameters = {
                    new SqlParameter("@FYear", SqlDbType.Decimal,5),
                    new SqlParameter("@FMonth", SqlDbType.Decimal,5),
                    new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
                    new SqlParameter("@FType", SqlDbType.NVarChar,20)};
            parameters[0].Value = year;
            parameters[1].Value = month;
            parameters[2].Value = emplNo;
            parameters[3].Value = entityNo;
            parameters[4].Value = type;
            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 获得主岗位部门
        /// </summary>
        /// <returns>数据列表</returns>
        public DataSet GetDept()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from  t_HRDept as a left join dbo.t_ICACDeptDoc  as b");
            strSql.Append(" on a.FDeptNo=b.FDeptNo and a.FEntityNo= b.FEntityNo");
            strSql.Append(" where a.FParentDeptNo is null and a.FIsAgency = 'N'");
            strSql.Append(" order by FSeq");
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 需要考核的部门（不是外派机构）
        /// </summary>
        /// <returns>数据列表</returns>
        public DataSet GetCheckDept()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from t_HRDept");
            strSql.Append(" where FIsAgency='N' and FParentDeptNo is null");
            strSql.Append(" order by FSeq");
            return DbHelperSQL.Query(strSql.ToString());

        }
        /// <summary>
        /// 需要考核人员
        /// </summary>
        /// <param name="fDeptNO">部门编号</param>
        /// <returns>数据列表</returns>
        public DataSet GetChechEmp(string fDeptNO)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from v_HRDeptEmpl");
            strSql.Append(" where FDeptNo=@FDeptNo and FIsMainPosition='Y' and FIsCheck ='Y' and FEmpStatus <> 99");
            strSql.Append(" order by FSeq,FDutyNo");

            SqlParameter[] parameters = {
					new SqlParameter("@FDeptNo", SqlDbType.NVarChar,15),
			};
            parameters[0].Value = fDeptNO;

            return DbHelperSQL.Query(strSql.ToString(), parameters);

        }
        /// <summary>
        /// 获取当前时间
        /// </summary>
        /// <returns></returns>
        public DataSet GetSysDate() 
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select GETDATE() as sysDate");
            return DbHelperSQL.Query(strSql.ToString());
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ElingOA6_Admin_DSJCJ.Model.MonthPlanSummary DataRowToModel(DataRow row)
        {
            ElingOA6_Admin_DSJCJ.Model.MonthPlanSummary model = new ElingOA6_Admin_DSJCJ.Model.MonthPlanSummary();
            if (row != null)
            {
                if (row["FMonthPlanSummaryID"] != null && row["FMonthPlanSummaryID"].ToString() != "")
                {
                    model.FMonthPlanSummaryID = decimal.Parse(row["FMonthPlanSummaryID"].ToString());
                }
                if (row["FEntityNo"] != null)
                {
                    model.FEntityNo = row["FEntityNo"].ToString();
                }
                if (row["FDeptNo"] != null)
                {
                    model.FDeptNo = row["FDeptNo"].ToString();
                }
                if (row["FEmplNo"] != null)
                {
                    model.FEmplNo = row["FEmplNo"].ToString();
                }
                if (row["FYear"] != null && row["FYear"].ToString() != "")
                {
                    model.FYear = decimal.Parse(row["FYear"].ToString());
                }
                if (row["FMonth"] != null && row["FMonth"].ToString() != "")
                {
                    model.FMonth = decimal.Parse(row["FMonth"].ToString());
                }
                if (row["FBeginDate"] != null && row["FBeginDate"].ToString() != "")
                {
                    model.FBeginDate = DateTime.Parse(row["FBeginDate"].ToString());
                }
                if (row["FEndDate"] != null && row["FEndDate"].ToString() != "")
                {
                    model.FEndDate = DateTime.Parse(row["FEndDate"].ToString());
                }
                if (row["FInsDate"] != null && row["FInsDate"].ToString() != "")
                {
                    model.FInsDate = DateTime.Parse(row["FInsDate"].ToString());
                }
                if (row["FUpdDate"] != null && row["FUpdDate"].ToString() != "")
                {
                    model.FUpdDate = DateTime.Parse(row["FUpdDate"].ToString());
                }
                if (row["FType"] != null)
                {
                    model.FType = row["FType"].ToString();
                }
                if (row["FContent"] != null)
                {
                    model.FContent = row["FContent"].ToString();
                }
                if (row["FInsIP"] != null)
                {
                    model.FInsIP = row["FInsIP"].ToString();
                }
                if (row["FAdditionalInsEmplNo"] != null)
                {
                    model.FAdditionalInsEmplNo = row["FAdditionalInsEmplNo"].ToString();
                }
                if (row["FAdditionalInsDate"] != null && row["FAdditionalInsDate"].ToString() != "")
                {
                    model.FAdditionalInsDate = DateTime.Parse(row["FAdditionalInsDate"].ToString());
                }
                if (row["FAdditionalInsIP"] != null)
                {
                    model.FAdditionalInsIP = row["FAdditionalInsIP"].ToString();
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FMonthPlanSummaryID,FEntityNo,FDeptNo,FEmplNo,FYear,FMonth,FBeginDate,FEndDate,FInsDate,FUpdDate,FType,FContent,FInsIP,FAdditionalInsEmplNo,FAdditionalInsDate,FAdditionalInsIP  ");
            strSql.Append(" FROM dbo.t_MonthPlanSummary ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }


        /// <summary>
        /// 得到工作人员的名字
        /// </summary>
        /// <param name="empNo">人员编号</param>
        /// <returns>字符</returns>
        public string GetEmpName(string empNo)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FEmpName from v_HRDeptEmpl");
            strSql.Append(" where FEmplNo=@FEmplNo");
            strSql.Append(" order by FSeq");

            SqlParameter[] parameters = {
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15),
			};
            parameters[0].Value = empNo;

            return DbHelperSQL.GetString(strSql.ToString(), parameters);

        }
        /// <summary>
        /// 获取是否能补录绩效考核
        /// </summary>
        /// <param name="empNo">人员编号</param>
        /// <returns>字符</returns>
        public string GetAllowAddtionInsPlan(string empNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FIsAllowAddtionInsPlan from t_HREmpl");
            strSql.Append(" where FEmplNo=@FEmplNo");
            strSql.Append(" order by FSeq");
            SqlParameter[] parameters = {
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15),
			};
            parameters[0].Value = empNo;

            return DbHelperSQL.GetString(strSql.ToString(), parameters);

        }

        /// <summary>
        /// 获取是否参与绩效考核
        /// </summary>
        /// <param name="empNo">人员编号</param>
        /// <returns>字符</returns>
        public string GetCheck(string empNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FIsCheck from t_HREmpl");
            strSql.Append(" where FEmplNo=@FEmplNo");
            strSql.Append(" order by FSeq");
            SqlParameter[] parameters = {
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15),
			};
            parameters[0].Value = empNo;

            return DbHelperSQL.GetString(strSql.ToString(), parameters);

        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ElingOA6_Admin_DSJCJ.Model.MonthPlanSummary GetModel(decimal year, decimal month, string emplNo, string entityNo, string type)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 FMonthPlanSummaryID,FEntityNo,FDeptNo,FEmplNo,FYear,FMonth,FBeginDate,FEndDate,FInsDate,FUpdDate,FType,FContent,FInsIP,FAdditionalInsEmplNo,FAdditionalInsDate,FAdditionalInsIP from dbo.t_MonthPlanSummary ");
            strSql.Append(" where FYear=@FYear and FMonth=@FMonth and FEmplNo=@FEmplNo and FEntityNo=@FEntityNo and FType=@FType");
            SqlParameter[] parameters = {
                    new SqlParameter("@FYear", SqlDbType.Decimal,5),
                    new SqlParameter("@FMonth", SqlDbType.Decimal,5),
                    new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
                    new SqlParameter("@FType", SqlDbType.NVarChar,20)};
            parameters[0].Value = year;
            parameters[1].Value = month;
            parameters[2].Value = emplNo;
            parameters[3].Value = entityNo;
            parameters[4].Value = type;

            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public decimal Add(ElingOA6_Admin_DSJCJ.Model.MonthPlanSummary model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into dbo.t_MonthPlanSummary(");
            strSql.Append("FEntityNo,FDeptNo,FEmplNo,FYear,FMonth,FBeginDate,FEndDate,FInsDate,FUpdDate,FType,FContent,FInsIP)");
            strSql.Append(" values (");
            strSql.Append("@FEntityNo,@FDeptNo,@FEmplNo,@FYear,@FMonth,@FBeginDate,@FEndDate,@FInsDate,@FUpdDate,@FType,@FContent,@FInsIP)");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FDeptNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FYear", SqlDbType.Decimal,5),
					new SqlParameter("@FMonth", SqlDbType.Decimal,5),
					new SqlParameter("@FBeginDate", SqlDbType.DateTime),
					new SqlParameter("@FEndDate", SqlDbType.DateTime),
					new SqlParameter("@FInsDate", SqlDbType.DateTime),
					new SqlParameter("@FUpdDate", SqlDbType.DateTime),
					new SqlParameter("@FType", SqlDbType.NVarChar,20),
					new SqlParameter("@FContent", SqlDbType.NVarChar,-1),
					new SqlParameter("@FInsIP", SqlDbType.NVarChar,15)};
            parameters[0].Value = model.FEntityNo;
            parameters[1].Value = model.FDeptNo;
            parameters[2].Value = model.FEmplNo;
            parameters[3].Value = model.FYear;
            parameters[4].Value = model.FMonth;
            parameters[5].Value = model.FBeginDate;
            parameters[6].Value = model.FEndDate;
            parameters[7].Value = model.FInsDate;
            parameters[8].Value = model.FUpdDate;
            parameters[9].Value = model.FType;
            parameters[10].Value = model.FContent;
            parameters[11].Value = model.FInsIP;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToDecimal(obj);
            }
        }
        /// <summary>
        /// 增加一条数据 补录
        /// </summary>
        public decimal Addition(ElingOA6_Admin_DSJCJ.Model.MonthPlanSummary model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into dbo.t_MonthPlanSummary(");
            strSql.Append("FEntityNo,FDeptNo,FEmplNo,FYear,FMonth,FBeginDate,FEndDate,FInsDate,FUpdDate,FType,FContent,FInsIP,FAdditionalInsEmplNo,FAdditionalInsDate,FAdditionalInsIP)");
            strSql.Append(" values (");
            strSql.Append("@FEntityNo,@FDeptNo,@FEmplNo,@FYear,@FMonth,@FBeginDate,@FEndDate,@FInsDate,@FUpdDate,@FType,@FContent,@FInsIP,@FAdditionalInsEmplNo,@FAdditionalInsDate,@FAdditionalInsIP)");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FDeptNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FYear", SqlDbType.Decimal,5),
					new SqlParameter("@FMonth", SqlDbType.Decimal,5),
					new SqlParameter("@FBeginDate", SqlDbType.DateTime),
					new SqlParameter("@FEndDate", SqlDbType.DateTime),
					new SqlParameter("@FInsDate", SqlDbType.DateTime),
					new SqlParameter("@FUpdDate", SqlDbType.DateTime),
					new SqlParameter("@FType", SqlDbType.NVarChar,20),
					new SqlParameter("@FContent", SqlDbType.NVarChar,-1),
					new SqlParameter("@FInsIP", SqlDbType.NVarChar,15),
					new SqlParameter("@FAdditionalInsEmplNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FAdditionalInsDate", SqlDbType.DateTime),
					new SqlParameter("@FAdditionalInsIP", SqlDbType.NVarChar,20)};
            parameters[0].Value = model.FEntityNo;
            parameters[1].Value = model.FDeptNo;
            parameters[2].Value = model.FEmplNo;
            parameters[3].Value = model.FYear;
            parameters[4].Value = model.FMonth;
            parameters[5].Value = model.FBeginDate;
            parameters[6].Value = model.FEndDate;
            parameters[7].Value = model.FInsDate;
            parameters[8].Value = model.FUpdDate;
            parameters[9].Value = model.FType;
            parameters[10].Value = model.FContent;
            parameters[11].Value = model.FInsIP;
            parameters[12].Value = model.FAdditionalInsEmplNo;
            parameters[13].Value = model.FAdditionalInsDate;
            parameters[14].Value = model.FAdditionalInsIP;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToDecimal(obj);
            }
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(ElingOA6_Admin_DSJCJ.Model.MonthPlanSummary model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update dbo.t_MonthPlanSummary set ");
            strSql.Append("FUpdDate=@FUpdDate,");
            strSql.Append("FContent=@FContent");
            strSql.Append(" where FYear=@FYear and FMonth=@FMonth and FEmplNo=@FEmplNo and FEntityNo=@FEntityNo and FType=@FType");
            SqlParameter[] parameters = {
					new SqlParameter("@FUpdDate", SqlDbType.DateTime),
					new SqlParameter("@FContent", SqlDbType.NVarChar,-1),
                    new SqlParameter("@FYear", SqlDbType.Decimal,5),
                    new SqlParameter("@FMonth", SqlDbType.Decimal,5),
                    new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
                    new SqlParameter("@FType", SqlDbType.NVarChar,20)};
            parameters[0].Value = model.FUpdDate;
            parameters[1].Value = model.FContent;
            parameters[2].Value = model.FYear;
            parameters[3].Value = model.FMonth;
            parameters[4].Value = model.FEmplNo;
            parameters[5].Value = model.FEntityNo;
            parameters[6].Value = model.FType;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 需要绩效考核的人员名单
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <returns></returns>
        public DataSet GetListByEntityNo(string entityNo, string startDate, string endDate)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select a.* from v_HRDeptEmpl a,dbo.t_HRDept b");
            strSql.Append(" WHERE a.FDeptNo=b.FDeptNo AND  a.FEntityNo=@FEntityNo and FIsMainPosition='Y'  ");
            strSql.Append("  and FIsCheck='Y' AND FEmpStatus <> '99' AND FIsAgency='N'");
            strSql.Append(@"   and ((FWorkDate IS NULL AND FLeaveDate IS NULL) 
OR (FWorkDate IS NOT NULL AND DATEDIFF(DAY,FWorkDate,@FEndDate1)>0 AND  FLeaveDate IS NULL)
OR (FLeaveDate IS NOT NULL AND DATEDIFF(DAY,FLeaveDate,@FBeginDate1)<0 AND FWorkDate IS NULL )
OR (FWorkDate IS NOT NULL AND FLeaveDate IS NOT NULL AND DATEDIFF(DAY,FWorkDate,@FEndDate2)>0  AND DATEDIFF(DAY,FLeaveDate,@FBeginDate2)<0))");
            strSql.Append("  order by a.FDeptNo,a.FSeq,FDutyNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
                    new SqlParameter("@FBeginDate1", SqlDbType.DateTime),
                    new SqlParameter("@FEndDate1", SqlDbType.DateTime),
                    new SqlParameter("@FBeginDate2", SqlDbType.DateTime),
                    new SqlParameter("@FEndDate2", SqlDbType.DateTime)};
            parameters[0].Value = entityNo;
            parameters[1].Value = startDate;
            parameters[2].Value = endDate;
            parameters[3].Value = startDate;
            parameters[4].Value = endDate;
            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 需要绩效考核的部门
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <returns></returns>
        public DataSet GetDeptListByEntityNo(string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select a.deptName,a.FDeptNo from v_HRDeptEmpl a,dbo.t_HRDept b");
            strSql.Append(" WHERE a.FDeptNo=b.FDeptNo AND  a.FEntityNo=@FEntityNo and FIsMainPosition='Y'");
            strSql.Append("  and FIsCheck='Y' AND FEmpStatus <> '99' AND FIsAgency='N'");
            strSql.Append(" GROUP BY a.deptName,a.FDeptNo ");
            strSql.Append(" order by a.FDeptNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12)};
            parameters[0].Value = entityNo;
            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="emplNo"></param>
        /// <param name="entityNo"></param>
        /// <returns></returns>
        public DataSet GetModelIsWork(string emplNo, string entityNo) 
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT FEntityNo,FEmplNo,FEmpName,FOfficeTel,FTelShortNo,FMobile,FMobShortNo,FEMail,FHomeTel,FHomeAddr,FSex,FIdNo,FBirthday,FNativePlace,FEduNo,FSchool,FSpecialty,FSeq,FPhoto,FDutyNo,FJob,FEmpStatus,FIsJoin,FLeaveDate,FIsCheck,FWorkDate,FIsAttendance,FIsAllowAddtionInsPlan");
            strSql.Append(" from t_HREmpl");
            strSql.Append(" where FEntityNo=@FEntityNo and FEmplNo=@FEmplNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)			};
            parameters[0].Value = entityNo;
            parameters[1].Value = emplNo;

            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 需要绩效考核的人员名单
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <returns></returns>
        public DataSet GetListByEntityNo(string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select a.* from v_HRDeptEmpl a,dbo.t_HRDept b");
            strSql.Append(" WHERE a.FDeptNo=b.FDeptNo AND  a.FEntityNo=@FEntityNo and FIsMainPosition='Y'  ");
            strSql.Append("  and FIsCheck='Y' AND FEmpStatus <> '99' AND FIsAgency='N'");
            strSql.Append("  order by a.FDeptNo,a.FSeq,FDutyNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12)};
            parameters[0].Value = entityNo;
            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 
        /// </summary>
        public void UpdataEmpl(List<Model.HREmpl> emplModelList)
        {
            StringBuilder strSql = new StringBuilder();
            CommandInfo cmds = new CommandInfo();
            List<CommandInfo> cmdList = new List<CommandInfo>();
            if (emplModelList.Count > 0)
            {
                strSql.Append(" update t_HREmpl set");
                strSql.Append(" FIsCheck=@FIsCheck");
                strSql.Append(" where FEntityNo=@FEntityNo and FEmplNo=@FEmplNo ");

                foreach (Model.HREmpl model in emplModelList)
                {

                    cmds = new CommandInfo();

                    SqlParameter[] parameters = {
                        new SqlParameter("@FIsCheck", SqlDbType.NVarChar,1),
					    new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					    new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)};
                    parameters[0].Value = model.FIsCheck;
                    parameters[1].Value = model.FEntityNo;
                    parameters[2].Value = model.FEmplNo;
                    cmds.CommandText = strSql.ToString();
                    cmds.Parameters = parameters;
                    cmdList.Add(cmds);
                }
            }
            if (cmdList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithString(cmdList);
            }
        }
        /// <summary>
        /// 允许补录其他人员的人员
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <returns></returns>
        public DataSet GetListAllowAddtionInsPlanByEntityNo(string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select a.* from v_HRDeptEmpl a,dbo.t_HRDept b");
            strSql.Append(" WHERE a.FDeptNo=b.FDeptNo AND  a.FEntityNo=@FEntityNo and FIsMainPosition='Y'  ");
            strSql.Append("  and FIsAllowAddtionInsPlan='Y' AND FEmpStatus <> '99' AND FIsAgency='N'");
            strSql.Append("  order by a.FDeptNo,a.FSeq,FDutyNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12)};
            parameters[0].Value = entityNo;
            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 更新
        /// </summary>
        public void UpdataEmplAllowAddtionInsPlan(List<Model.HREmpl> emplModelList)
        {
            StringBuilder strSql = new StringBuilder();
            CommandInfo cmds = new CommandInfo();
            List<CommandInfo> cmdList = new List<CommandInfo>();
            if (emplModelList.Count > 0)
            {
                strSql.Append(" update t_HREmpl set");
                strSql.Append(" FIsAllowAddtionInsPlan=@FIsAllowAddtionInsPlan");
                strSql.Append(" where FEntityNo=@FEntityNo and FEmplNo=@FEmplNo ");

                foreach (Model.HREmpl model in emplModelList)
                {

                    cmds = new CommandInfo();

                    SqlParameter[] parameters = {
                        new SqlParameter("@FIsAllowAddtionInsPlan", SqlDbType.NVarChar,1),
					    new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					    new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)};
                    parameters[0].Value = model.FIsAllowAddtionInsPlan;
                    parameters[1].Value = model.FEntityNo;
                    parameters[2].Value = model.FEmplNo;
                    cmds.CommandText = strSql.ToString();
                    cmds.Parameters = parameters;
                    cmdList.Add(cmds);
                }
            }
            if (cmdList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithString(cmdList);
            }
        }

    }
}
